package com.angus.modules.front.mapper;

import com.angus.api.front.domain.FrontUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author liyanan
 * @date 2024/10/15 1:39 PM
 * @description
 */
@Repository
public interface FrontUserMapper extends BaseMapper<FrontUser> {
    @Select("<script>" +
            "select " +
            "   u.*, " +
            "   o.expire_time " +
            "from " +
            "   front_user as u " +
            "left join (" +
            "   select " +
            "       user_id, MAX(expire_time) as expire_time " +
            "   from sys_order " +
            "   where " +
            "       `status`  = 2 " +
            "       and del_flag = 0 " +
            "   group by " +
            "       user_id" +
            ") o on u.user_id = o.user_id " +
            "where u.del_flag = 0 " +
            "<if test='keyword != null and keyword != &quot;&quot;'>" +
            "   and (u.user_name like #{keyword} or " +
            "   u.nick_name like #{keyword} or " +
            "   u.phone_number like #{keyword} or " +
            "   u.user_email like #{keyword})" +
            "</if>" +
            "<if test='status != null and status != &quot;&quot;'>" +
                " and u.status = #{status}" +
            "</if>" +
            "</script>")
    List<FrontUser> getUserList(
            @Param("keyword") String keyword,
            @Param("status") Integer status
    );
}
